package tech.aistar.wyymusicplayer.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tech.aistar.wyymusicplayer.pojo.PlayListDetails;
import tech.aistar.wyymusicplayer.pojo.Result;
import tech.aistar.wyymusicplayer.pojo.Song;
import tech.aistar.wyymusicplayer.service.SongService;

import java.util.List;

@RestController
@RequestMapping("song")
public class SongController {

    @Autowired
    private SongService songService;

//    @GetMapping("/{songId}")
//    public Result getSongById(@PathVariable Integer songId) {
//        Song song = songService.selectById(songId); // 确保实现
//        return new Result("200","成功获取歌曲信息", song);
//    }

    @GetMapping("/playlistSongs")
    public Result getSongsByPlaylistId(@RequestParam Integer playlistId) {
        List<Song> songs = songService.getSongsByPlaylistId(playlistId);
        return new Result("200", "成功获取歌曲列表", songs);
    }

    @GetMapping("/{songId}")
    public Result getSongDetail(@PathVariable Integer songId) {
        Song song = songService.findSongById(songId);
        if (song == null) {
            return new Result("404", "歌曲不存在", null);
        }
        return new Result("200", "成功获取歌曲信息", song);
    }

    @GetMapping
    public Result index(HttpServletRequest request) {
        //从request作用域中将Id获取出来
        Integer id = (Integer) request.getAttribute("id");
        Song songList = songService.findSongById(1);
        System.out.println(songList);
        return new Result("200","登录用户的歌单信息!",songList);
    }
    @PostMapping
    public Result showSongs(){
        return new Result("200","成功获取",songService.selectByTitle("%"));
    }
}
